package com.mrobuy.jd.api.category;

import com.jd.open.api.sdk.JdClient;
import com.mrobuy.jd.api.JosClient;
import com.mrobuy.jd.sdk.domain.SaleAttributeDto;
import com.mrobuy.jd.sdk.request.VcItemSaleAttributeSettingsGetRequest;
import com.mrobuy.jd.sdk.response.VcItemSaleAttributeSettingsGetResponse;
import com.mrobuy.jdvc.entity.VCCategorySaleProp;
import com.mrobuy.util.IdentifierGen;

import java.util.ArrayList;
import java.util.List;

/**
 *  获取我的类目列表
 *
 *  jingdong.vc.item.products.find
 *
 *  <url>https://open.jd.com/home/home#/doc/api?apiCateId=86&apiId=1681&apiName=jingdong.vc.item.products.find</url>
 *
 *
 *
 */
public class SalePropFindClient extends JosClient<List<VCCategorySaleProp>> {

    private VcItemSaleAttributeSettingsGetRequest request=new VcItemSaleAttributeSettingsGetRequest();

    public SalePropFindClient(JdClient client) {
        super(client);
    }

    @Override
    public List<VCCategorySaleProp> call() throws Exception {

        List<VCCategorySaleProp> result = new ArrayList<>();

        VcItemSaleAttributeSettingsGetResponse response = client.execute(request);
        if ( response.getJosResultDto().getSuccess() ) {

            for (SaleAttributeDto saleAttributeDto : response.getJosResultDto().getResult()) {
                VCCategorySaleProp saleProp = new VCCategorySaleProp();
                saleProp.setCid(request.getCid3());
                saleProp.setDim(saleAttributeDto.getAttrDim());
                saleProp.setName(saleAttributeDto.getAttrValue());
                result.add(saleProp);
            }
        }

        return result;
    }



    public SalePropFindClient setCid3(int cid3) {
        request.setCid3(cid3);
        return this;
    }
}
